﻿
using Assets.Scripts.Manager;
using System;
using UnityEngine;
using UnityEngine.UI;

public class StartUI : UIBase
{
    public override void OnOpen(Action onComplete)
    {
        this.gameObject.SetActive(true);
        InputManager.Instance.OnSelectClickEvent += OnSelectClicked;
        InputManager.Instance.OnStartClickEvent += OnStartClicked;
       
    }
    public override void OnClose(Action onComplete)
    {
        this.gameObject.SetActive(false);
        InputManager.Instance.OnSelectClickEvent -= OnSelectClicked;
        InputManager.Instance.OnStartClickEvent -= OnStartClicked;
    }

    [SerializeField] private Image _startIcon;
    //[SerializeField] private Image _start;

    [SerializeField] private Image _continueIcon;
    //[SerializeField] private Image _continue;


    private int _selectIndex = 0;

    private void OnStartClicked()
    {
        if (_selectIndex == 0)
        {
            _selectIndex = 1;
        }
        else if (_selectIndex == 1)
        {
            _selectIndex = 0;
        }
        Show(_selectIndex);
    }
    public void Show(int i = 0)
    {
        switch (i)
        {
            case 0:
                _startIcon.gameObject.SetActive(true);
                _continueIcon.gameObject.SetActive(false);
                break;
            case 1:
                _startIcon.gameObject.SetActive(false);
                _continueIcon.gameObject.SetActive(true);
                break;
            default:
                break;
        }
        _selectIndex = i;
    }

    private void OnSelectClicked()
    {
        Click();
    }

    public void Click()
    {
        switch (_selectIndex)
        {
            case 0:
                GameMgr.Instance.StartGame();
                break;
            case 1:
                //继续游戏
                break;
        }
    }
}

